package com.sansi.bleFloodlight.adapter;

import android.text.TextUtils;

import com.a1anwang.okble.client.scan.BLEScanResult;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sansi.bleFloodlight.R;

import java.util.List;

public class ConnectLightAdapter extends BaseQuickAdapter<BLEScanResult, BaseViewHolder> {

    private  List<Integer> connectList;

    public ConnectLightAdapter() {
        super(R.layout.layout_item_connect_light);
    }

    @Override
    protected void convert(final BaseViewHolder helper, BLEScanResult myDevice) {
        helper.setText(R.id.tv_device_name,  TextUtils.isEmpty(myDevice.getBluetoothDevice().getName()) ?
                myDevice.getBluetoothDevice().getAddress() : myDevice.getBluetoothDevice().getName());
        helper.setVisible(R.id.iv_connect_result,true);
        helper.setVisible(R.id.loading,false);
        if(connectList.get(helper.getLayoutPosition())==0){
            helper.setVisible(R.id.loading,true);
            helper.setVisible(R.id.iv_connect_result,false);
        }else if(connectList.get(helper.getLayoutPosition())==1){
            helper.setImageResource(R.id.iv_connect_result,R.drawable.tjcg);
        }else{
            helper.setImageResource(R.id.iv_connect_result,R.drawable.tjsb);
        }
    }

    public void setNewData(List<BLEScanResult> listData, List<Integer> connectList){
        this.connectList=connectList;
        super.setNewData(listData);
    }


}
